<?php

/*
  Project     : 48c6c450f1a4a0cc53d9585dc0fee742
  Created on  : Mar 16, 2013, 11:29:15 PM
  Author      : Truong Khuong - khuongxuantruong@gmail.com
  Description :
  Purpose of the stylesheet follows.
 */

class privilege_model extends CI_Model {
    private $table;
    function __construct()
    {
        parent::__construct();
    }
    function get($_id){
        $query=$this->db
                ->where("apri_id",$_id)
                ->get("auth_privileges");
        $error_number = $this->db->_error_number();
        $error_message = $this->db->_error_message();
        if($error_number!==0){
            $_SESSION['auth_db']['errors'][]=$error_message;
            return null;
        }
        $rs = $query->result();
        if(isset($rs[0]))   {
            return $rs[0];
        }
        return null;
    }
    function gets(){
        $query=$this->db
                ->where('apri_delete',null)
                ->order_by('apri_position','DESC')
                ->order_by('apri_insert','DESC')
                ->get('auth_privileges');
        $error_number = $this->db->_error_number();
        $error_message = $this->db->_error_message();
        if($error_number!==0){
            $_SESSION['auth_db']['errors'][]=$error_message;
            return null;
        }
        $rs = $query->result();
        return $rs;
    }
    function insert_onduplicate_update_apri($aParamsi,$aUpdate){
        $this->db->on_duplicate_update('auth_privileges', $aUpdate, $aParamsi); 
        $count = $this->db->affected_rows();
		$error_number = $this->db->_error_number();
        $error_message = $this->db->_error_message();
        if($error_number!==0){
            $_SESSION['auth_db']['errors'][]=$error_message;
            return false;
        }
        if($count>0) return $count;
        return false;
    }
    function insert($params){
        //$this->db->set('_insert', 'NOW()', FALSE);
        @$this->db->insert("auth_privileges", $params); 
		$error_number = $this->db->_error_number();
        $error_message = $this->db->_error_message();
        if($error_number!==0){
            $_SESSION['auth_db']['errors'][]=$error_message;
            return false;
        }
        @$count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function delete($ID){
        $this->db->set('apri_delete', 'NOW()', FALSE);
        $where=array('apri_id'=>$ID);
        $this->db->where($where);
        $this->db->update("auth_privileges"); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function retore($ID){
        $this->db->set('apri_delete', 'NULL', FALSE);
        $where=array('apri_id'=>$ID);
        $this->db->where($where);
        $this->db->update("auth_privileges"); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function update($ID,$params){
        //$this->db->set('_update', 'NOW()', FALSE);
        $this->db->where('apri_id', $ID);
        @$this->db->update("auth_privileges", $params); 
		$error_number = $this->db->_error_number();
        $error_message = $this->db->_error_message();
        if($error_number!==0){
            $_SESSION['auth_db']['errors'][]=$error_message;
            return false;
        }
        @$count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
}

?>
